<template>
  <div class="updata-photo">
    <div class="cancel" @click="$emit('close')">取消</div>
    <div class="confirm" @click="onConfirm">完成</div>
    <div class="ccch"></div>
    <van-uploader :after-read="afterRead" v-model="fileList" multiple />
  </div>
</template>

<script>
// import store from "@/store";
// import { reRefrash_token } from "@/utils/setToken";
// import { mapMutations } from "vuex";
// import { updataUsername } from "@/api/user";

export default {
  name: "UpdatePhoto",
  components: {},
  props: {
    value: {
      type: [String],
    },
  },
  data() {
    return {
      fileList: [
        // Uploader 根据文件后缀来判断是否为图片文件
        { url: this.value },
      ],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // ...mapMutations("user", ["setToken"]),
    afterRead(file) {
      // 此时可以自行将文件上传至服务器
      console.log(file);
      console.log(this.value);

      // this.$emit("input", this.birth);
      // const formData = new FormData();
      // formData.append("photo", file);
      // const data = await updataUsername(
      //   store.getters.id,
      //   reRefrash_token({ user_photo: formData })
      // );
      // console.log(data);
      // this.$toast.success("修改成功");
      // this.setToken(reRefrash_token({ user_birth: this.value }));
      // this.$emit("close");
    },
    onConfirm() {
      this.$emit("close");
      this.$toast.success("修改成功");
    },
  },
};
</script>
<style lang='less' scoped>
.ccch {
  height: 40px;
}
.cancel {
  float: left;
  font-size: 18px;
}
.confirm {
  float: right;
  font-size: 18px;
}
</style>
